{layout name="common/layout" /}
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a></div>
<style>
	.editer{
		margin-left: 0px;
	}
	input {
		font-size: 14px;
		color: #222;
		margin: -5px 0 0 10px;
		outline: none;
		border: none;
	}
	.lab{
		margin-left: 60px;;
	}
</style>
<div class="Hui-article-box" style="margin-top: 37px;">
	<div class="breadcrumb"><i class="Hui-iconfont"></i> <a href="{:url('book/borrowOrder')}" class="maincolor">图书交易管理</a>
		<span class="c-999 en">&gt;</span>
	</div>
	<div class="Hui-article">
		<div class="jiesuan">
			<div class="recond-titles">
				<h3 style="margin:10px 0 10px 16px;font-size: 18px;">结算单</h3>
			</div>
			<div class="jie-text">
				<form id="frm" method="post" enctype="multipart/form-data" style="border:0;"  class="form-horizontal" action="{:url('order/jiesuan_add')}">
					<input type="hidden" name="order_id" value="{$jiesuan_orderinfo.id}" />
					<input type="hidden" name="books_id" value="{$jiesuan_orderinfo.books_id}" />
					<input type="hidden" name="lose_books" value="" />
				    <div class="lab cl">
						<div class="lab-l">
							<span class="span">会员卡：</span>
						</div>
						<div class="lab-r" style="width: 300px;height: 30px;border:0px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: left;">
							{if condition="$jiesuan_orderinfo.pay_type eq '0'"}
							{switch name="$jiesuan_orderinfo.rank"}
							{case value="1"}小状元计划{/case}
							{case value="2"}小博士计划{/case}
							{case value="3"}免费体验计划{/case}
							{/switch}
							-
							{switch name="$jiesuan_orderinfo.type"}
							{case value="1"}月卡{/case}
							{case value="2"}季卡{/case}
							{case value="3"}半年卡{/case}
							{case value="4"}年卡{/case}
							{/switch}
							({$jiesuan_orderinfo.card_no})
							{else/}
							绘本直购
							{/if}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">用户：</span>
						</div>
						<div class="lab-r" style="width: 300px;height: 30px;border:0px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: left;">
							{$jiesuan_orderinfo.user_phone}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">图书列表({$jiesuan_orderinfo.book_num}本)：</span>
						</div>
						<div class="lab-r" style="width: 700px;height: 300px;overflow:auto;border:0px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: left;">

							<table style="text-align:left;width:95%;word-wrap: break-word;">
								<thead style="text-align: center;">
									<td>损坏&遗失</td>
									<td>封面</td>
									<td>图书</td>
									<td>出版社</td>
									<td>ISBN</td>
								</thead>
								{foreach $jiesuan_orderinfo.book_list as $k => $v}
								<tr>
									<td>
										<input type="checkbox" class="lose_book" data-id="{$v['id']}" <?php if(isset($v['is_sale']) && $v['is_sale'] == 1){echo "checked";}?> style="width: 18px;height: 18px;"/>
									</td>
									<td style="position: relative;bottom:3px;">
										<a href="{:url('Book/updateBook')}?bookid={$v['id']}">
										<span style="margin-left: 0px;">
											<img style="width:45px;height: 60px;padding-right: 10px;" src="{$v['img_medium']}"/>
										</span>
										</a>
									</td>
									<td>
										<a href="{:url('Book/updateBook')}?bookid={$v['id']}">《{$v['title']}》</a>
										<?php if(isset($v['is_sale']) && $v['is_sale'] == 1){?>
										<font style="color:red;">已被用户买下</font>
										<?php }?>
									</td>
									<td>{$v['publisher']}</td>
									<td>{$v['isbn13']}</td>
								</tr>
								{/foreach}
							</table>
							<!--
							<a href="{:url('Book/updateBook')}?bookid={$v['id']}">
							<p class="p-te">
								<span style="margin-left: 0px;">
									<img style="width:45px;height: 60px;padding-right: 10px;" src="{$v['img_medium']}"/>
								</span>
								<span style="margin-left: 70px;">《{$v['title']}》</span>
								<span style="margin-left: 20px;">{$v['publisher']}</span>
								<span style="margin-left: 20px;">ISBN:{$v['isbn13']}</span>
							</p>
							</a>
							-->
								<!--<p style="color: black;"><img style="width:45px;height: 60px;padding-right: 10px;" src="{$v['img_medium']}"/>{$v['title']}</p>-->

						</div>
					</div>
					{if condition="$jiesuan_orderinfo.pay_type neq '0'"}
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">合计租金：</span>
						</div>
						<div class="lab-r" style="width: 225px;height: 30px;border:1px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: right;">
							￥{$jiesuan_orderinfo.rent_price}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">平台优惠券：</span>
						</div>
						<div class="lab-r" style="width: 225px;height: 30px;border:1px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: right;">
							￥{$jiesuan_orderinfo.coupon_amount}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">押金：</span>
						</div>
						<div class="lab-r" style="width: 225px;height: 30px;border:1px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: right;">
							￥{$jiesuan_orderinfo.deposit}{if condition="$jiesuan_orderinfo.deposit_relief gt '0'"}(芝麻信用减免{$jiesuan_orderinfo.deposit}){/if}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">损坏赔偿金：</span>
						</div>
						<div class="lab-r" style="border:0;margin-top: 5px;">
							<input onpropertychange="adds()" oninput="adds()" type="text" name="liquidated" class="input-text radius size-M breaks" style="width: 225px;margin-bottom: 0;margin-top: 0;text-align: right;margin-left: 0px;" placeholder="+￥0.00"><br>
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">违约金：</span>
						</div>
						<div class="lab-r" style="border:0;margin-top: 5px;">
							<input type="text" onpropertychange="adds()" oninput="adds()" name="damages" class="input-text radius size-M lose" placeholder="￥0.00" style="width: 225px;text-align: right;margin-top: -4px;margin-left: 0px;"><br>
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">运费：</span>
						</div>
						<div class="lab-r fare" style="width: 225px;height: 30px;border:1px solid #e8e8e8;margin-top: 5px;border-radius: 6px;text-align: right;">
							￥{$jiesuan_orderinfo.freight}
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">小计：</span>
						</div>
						<div class="lab-r" style="border:0;margin-top: 5px;">
							<input type="text" class="total" name="total" style="width: 225px;margin-top: 0px;margin-left: 0px;height: 30px;border:1px solid #e8e8e8;float: left;border-radius: 6px;text-align: right; " readonly="readonly">
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">实际退款金额：</span>
						</div>
						<div class="lab-r" style="border:0;margin-top: 5px;">
							<input type="text" class="actual_total" style="margin-top: 0px;width: 225px;height: 30px;border:1px solid #e8e8e8;float: left;margin-left: 0px;border-radius: 6px;text-align: right; " readonly="readonly">
						</div>
					</div>
					<div class="lab cl">
						<div class="lab-l">
							<span class="span">备注：</span>
						</div>
						<div class="lab-r" style="border:0;margin-top: 5px;">
							<input type="text" name="remarks" class="input-text radius size-XL" placeholder="请备注违约金 损坏赔偿金产生的原因" style="height: 30px;font-size: 12px;margin-left: 0px">
						</div>
					</div>
					{/if}

					<button class="box-btn btn1" type="button" onClick="save();">确认</button>
					<button class="box-btn btn1"  style="margin-top: -40px;margin-left: 440px;" type="button" onclick="history.go(-1)">取消</button>
				</form>
			</div>
		</div>
	</div>			
</div>
<script>
    adds();
    function adds(){
        var rent="{$jiesuan_orderinfo.rent_price}";//总租金
        var breaks=$('.breaks').val();
        var lose=$('.lose').val();
        var fare=$('.fare').html().split('￥')[1];
        var s1=parseFloat(rent);
        var total = '';
        if(breaks== '' && lose!=''){
            total=s1*10+parseFloat(fare)*10+parseFloat(lose)*10;
        }else if(lose=='' && breaks!=''){
            lose='0';
            total=s1*10+parseFloat(fare)*10+parseFloat(breaks)*10;
        }else if(lose=='' && breaks==''){
            lose='0';
            total=s1*10+parseFloat(fare)*10;
        }else{
            total=s1*10+parseFloat(breaks)*10+parseFloat(fare)*10+parseFloat(lose)*10;
        }
        total = ((total)/10).toFixed(2);
        $('.total').val(total);
        var deposit = parseFloat("{$jiesuan_orderinfo.deposit}");
        var total_price = deposit+s1;

        $('.actual_total').val((total_price-total).toFixed(2));
    }
    function save()
	{
        var total = parseFloat( $("input[name='total']").val());
        if(total<0)
        {
            layer.msg("结算小计金额不能小于0!");
            return;
        }
        var c_total = parseFloat("{$jiesuan_orderinfo.rent_price}");
        if(total > c_total )
        {
            layer.msg("结算小计金额不能大于实付款！");
            return;
        }
        var lose_book = "";
        $(".lose_book").each(function () {
			if($(this).prop("checked") == true){
                lose_book += $(this).attr("data-id")+",";
			}
        });
        $("input[name='lose_books']").val(lose_book.replace(/(^,*)|(,*$)/g, ""));

        $.ajax({
			type: "POST",
			url: "<?php echo url('book/jiesuanHandle', '', false); ?>",
			dataType: 'json',
			cache: false,
			data: $('#frm').serialize(),
			success: function(data) {
				if(data.status == 1)
				{
					layer.msg("结算成功!");
					location.href="{:url('book/borrowOrder')}?type=1";
				}else{
					layer.msg(data.msg);
				}
			},
			error: function(xhr, status, error) {
				console.log(xhr);
				console.log(status);
				console.log(error);
			}
        });
	 
	}
	
	
</script>
